package algorithm.classification.evaluation;

import tools.Pair;
import data.set.OfflineSet;
import data.set.OfflineSetIterator;
import data.vectors.DoubleVector;
import algorithm.Classifier;

public class BinaryClassifierEvaluation<X> {

	private Classifier<X, Boolean> classifier;
	private OfflineSet<Pair<X, Boolean>> data;

	
	private int TP = 0;
	private int FP = 0; // fausse alertes
	private int TN = 0;
	private int FN = 0;
	
	public BinaryClassifierEvaluation(Classifier<X, Boolean> classifier,
			OfflineSet<Pair<X, Boolean>> data) {
		super();
		this.classifier = classifier;
		this.data = data;
	}




	public double[] evaluate() {
		OfflineSetIterator<Pair<X, Boolean>> iter = data.inputsetiterator();
		
		while(iter.hasNext()){
			iter.next();
			int id = iter.getCurrentId();
			X doc = iter.getCurrentObject().getX();
			
			boolean pred = classifier.map(doc);
			
			if(pred == true && iter.getCurrentObject().getY())
				TP++;
			else if(pred == true && !iter.getCurrentObject().getY())
				FP++;
			else if(pred == false && iter.getCurrentObject().getY())
				FN++;
			else if(pred == false && !iter.getCurrentObject().getY())
				TN++;
		}
		
		return new double[]{TP/(double)(TP+TN+FN+FP),FP/(double)(TP+TN+FN+FP),
				FN/(double)(TP+TN+FN+FP),TN/(double)(TP+TN+FN+FP)}; //(TP+TN)/(double)(TP+TN+FN+FP);
		
	}
	
}
